package com.angel.dtoutlis;

import com.angel.bean.Employee;
import com.angel.bean.EmployeeType;
import com.angel.dto.EmployeeDto;

import java.awt.*;
import java.util.ArrayList;
import java.util.List;

public class EmployeeDtoUtil {

    /**
     * 将员工和员工岗位进行dto封装
     *
     * @param employeeList 员工集合
     * @param etlist       岗位集合
     * @return dto集合
     */
    public static List<EmployeeDto> getEmployeeDto(List<Employee> employeeList, List<EmployeeType> etlist) {
        if (isNull(employeeList) || isNull(etlist)) {
            return null;
        }
        List<EmployeeDto> dtoList = new ArrayList<>();
        //Java8 lambda表达式写法
      /*  employeeList.forEach(employee -> {
            etlist.forEach(employeeType -> {
                if (employee.getEmTypeId().equals(employeeType.getEmTypeId())) {
                    dtoList.add(new EmployeeDto(employee, employeeType));
                }
            });
        });*/

        //普通写法与lamada表达式写法结果一样
        for (int i = 0; i < employeeList.size(); i++) {
            for (int j = 0; j < etlist.size(); j++) {
                if (employeeList.get(i).getEmTypeId().equals(etlist.get(j).getEmTypeId())) {
                    dtoList.add(new EmployeeDto(employeeList.get(i), etlist.get(j)));
                }
            }
        }

        return dtoList;
    }


    /**
     * 判断传入集合是否是空值
     *
     * @param list
     * @return
     */
    private static boolean isNull(List list) {
        if (list == null || list.isEmpty()) {
            return true;
        }
        return false;
    }
}
